from flask import *
import codecs,json,sys,os


app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False


@app.route('/')
def index():
    return render_template('main.html')

@app.route('/knowledge',methods=['GET'])
def knowledge():
    text=request.args.get("wd")
    output_data = codecs.open("data/resource/zzz.txt", 'w', 'utf-8')
    output_data.write(text)
    output_data.close()
    os.system("sh /home/xy/Downloads/knowledge-dialogue/generative_pt/run_test.sh")
    return text


@app.route('/getdata',methods=['GET','POST'])                       ##将数据从后端传到前端
def getdata():
    input = codecs.open("output/predict.txt", 'r', 'utf-8')
    for line in input.readlines():
        text=line
    return text

@app.errorhandler(500)
def error(e):
    return render_template('500.html'), 500

if __name__ == '__main__':
    print(app.url_map)
    # app.run(port=8889, debug=True,host='0.0.0.0')
    app.run(port=8888, debug=True)
